﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using NewDDSys.Entity;
using NewDDSys.IBLL;
using NewDDSys.IDAL;
using NewDDSys.Factory;
using NewDDSys.Utility;
using AjaxControlToolkit;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Web_KFGCdt : System.Web.UI.Page
{
    private string num = "";
    private DateTime pd;
    private int cs = 0;
    private string ku = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        num = Request.QueryString["Num"];
        DataSet ds = BLLFactory.CreateWorkBLL().Select(num);
        if (ds == null)
            Response.Write(" <script   language=javascript> window.alert( '无此记录，请联系管理员！ ');</script> ");
        else
        {
            txtNUM.Text = num;
            txtNUM.Attributes["contentEditable"] = "false";
            txtBanbie.Text = ds.Tables[0].Rows[0]["banbie"].ToString();
            txtBanbie.Attributes["contentEditable"] = "false";
            txtBanzu.Text = ds.Tables[0].Rows[0]["banzu"].ToString();
            txtBanzu.Attributes["contentEditable"] = "false";
            txtTianbao.Text = ds.Tables[0].Rows[0]["tianbao"].ToString();
            txtTianbao.Attributes["contentEditable"] = "false";
            txtKu.Text = ds.Tables[0].Rows[0]["ku"].ToString();
            ku = txtKu.Text.ToString();
            txtKu.Attributes["contentEditable"] = "false";
            txtDun.Text = ds.Tables[0].Rows[0]["dun"].ToString();
            txtDun.Attributes["contentEditable"] = "false";
            txtNeirong.Text = ds.Tables[0].Rows[0]["neirong"].ToString();
            txtNeirong.Attributes["contentEditable"] = "false";
            txtPos.Text = ds.Tables[0].Rows[0]["pos"].ToString();
            txtPos.Attributes["contentEditable"] = "false";
            txtPDtime.Text = ds.Tables[0].Rows[0]["pdtime"].ToString();
            pd = Convert.ToDateTime(txtPDtime.Text.ToString());
            txtPDtime.Attributes["contentEditable"] = "false";
            txtWcs.Text = ds.Tables[0].Rows[0]["wcs"].ToString();
            txtWcs.Attributes["contentEditable"] = "false";
            
            txtGood.Text = ds.Tables[0].Rows[0]["good"].ToString();
            cs = Convert.ToInt32(txtGood.Text.ToString());
            txtGood.Attributes["contentEditable"] = "false";
            txtBad.Text = ds.Tables[0].Rows[0]["bad"].ToString();
            txtBad.Attributes["contentEditable"] = "false";
            txtPb.Text = ds.Tables[0].Rows[0]["pb"].ToString();
            txtPb.Attributes["contentEditable"] = "false";
            txtCc.Text = ds.Tables[0].Rows[0]["cc"].ToString();
            txtCc.Attributes["contentEditable"] = "false";
            txtKx.Text = ds.Tables[0].Rows[0]["kx"].ToString();
            txtKx.Attributes["contentEditable"] = "false";
            txtZW.Text = ds.Tables[0].Rows[0]["zwtime"].ToString();
            txtZW.Attributes["contentEditable"] = "false";
            txtFW.Text = ds.Tables[0].Rows[0]["fwtime"].ToString();
            txtYuanyin.Text = ds.Tables[0].Rows[0]["yuanyin"].ToString();
        }
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string gctime = DateTime.Now.ToString();
        int f = BLLFactory.CreateWorkBLL().UpdateGc(num, gctime);
        if (f >= 1)
        {
            Response.Write(" <script   language=javascript> window.alert( ' 已挂出！ ');</script> ");
        }
        
        string sta = "挂出";
        BLLFactory.CreateWorkBLL().UpdateSta(num, sta);
        Response.Redirect(string.Format("WORK.aspx?Sta={0}", sta));
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string fw = txtFW.Text.ToString();
        string yuanyin = txtYuanyin.Text.ToString();
        int f = BLLFactory.CreateWorkBLL().UpdateFW(num, fw, yuanyin);
        if (f >= 1)
        {
            Response.Write(" <script   language=javascript> window.alert( ' 封完时间、原因已更改！ ');</script> ");
            TimeSpan ts = Convert.ToDateTime(fw) - pd;
            decimal hs = Convert.ToDecimal(ts.TotalHours.ToString("f"));
            switch (ku)
            {
                case "不锈钢冷轧库":
                case "酸洗库":
                    {



                        if (cs <= 6)
                        {
                            decimal yst = hs - Convert.ToDecimal(0.5 * cs + 4.5);
                            BLLFactory.CreateWorkBLL().UpdateYs(num, yst);
                        }
                        else if (cs <= 10)
                        {
                            decimal yst = hs - Convert.ToDecimal(5.5 + 0.5 * cs + 0.16 * (cs - 6));
                            BLLFactory.CreateWorkBLL().UpdateYs(num, yst);
                        }
                        else
                        {
                            decimal yst = hs - Convert.ToDecimal(1.5 + 4 + 0.33 * (cs - 10) + 0.5 * cs);
                            BLLFactory.CreateWorkBLL().UpdateYs(num, yst);
                        }
                    }; break;
                case "不锈钢热轧库":
                case "碳钢热轧库":
                case "嘉东卷板":
                    {

                        if (cs <= 6)
                        {
                            decimal yst = hs - Convert.ToDecimal(0.5 * cs);
                            BLLFactory.CreateWorkBLL().UpdateYs(num, yst);
                        }
                        else
                        {
                            decimal yst = hs - 4;
                            BLLFactory.CreateWorkBLL().UpdateYs(num, yst);
                        }
                    }; break;
                case "碳钢冷轧库":
                    {
                        if (cs <= 6)
                        {
                            decimal yst = hs - Convert.ToDecimal(0.5 * cs + 1);
                            BLLFactory.CreateWorkBLL().UpdateYs(num, yst);
                        }
                        else if (cs <= 10)
                        {
                            decimal yst = hs - 5;
                            BLLFactory.CreateWorkBLL().UpdateYs(num, yst);
                        }
                        else
                        {
                            decimal yst = hs - Convert.ToDecimal(5 + 0.33 * (cs - 10));
                            BLLFactory.CreateWorkBLL().UpdateYs(num, yst);
                        }
                    }; break;

                default:
                    break;
            }
        }
        Response.Redirect(string.Format("WORK.aspx?Sta={0}", "封完"));
    }
}
